package com.da.javatest.leetCode;

import java.util.Arrays;

/**
 * @author chenlida
 * @date 2019/1/10 11:27
 * @description
 */
public class Code389 {
    public char findTheDifference(String s, String t) {
        char[] c1 = s.toCharArray();
        char[] c2 = t.toCharArray();
        Arrays.sort(c1);
        Arrays.sort(c2);
        int l1 = c1.length;
        int l2 = c2.length;
        if (l1 > l2) {
            for (int i = 0; i < l2; i++) {
                if (c1[i] != c2[i]) {
                    return c1[i];
                }
            }
            return c1[l1 - 1];
        }
        for (int i = 0; i < l1; i++) {
            if (c1[i] != c2[i]) {
                return c2[i];
            }
        }
        return c2[l2 - 1];
    }
}
